package com.moyun.zbmy.zizhou.ui.adapter.holder;

import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.beans.FProgram;
import com.moyun.zbmy.zizhou.beans.LookBackBean;
import com.moyun.zbmy.zizhou.ui.widget.BasePlayerView;

public class LookBackNewsHolder extends RecyclerView.ViewHolder {
    public RelativeLayout columnLayout;
    public CustomFontTextView columnName;
    public BasePlayerView videoPlayer;
    public CustomFontTextView programTitle;
    public CustomFontTextView programDate;
    public LinearLayout bottomTitleLayout;
    public View playerBg;
    private OnColumnClickListener listener;
    private OnColumnItemClickListener itemClicklistener;
    private FProgram fProgram;

    public LookBackNewsHolder(View view) {
        super(view);
//        itemView.setOnClickListener(this);
        this.listener = listener;
        this.itemClicklistener = itemClicklistener;
        playerBg = (View) view.findViewById(R.id.item_play);
        videoPlayer = (BasePlayerView) view.findViewById(R.id.video_player);
        columnLayout = (RelativeLayout) view.findViewById(R.id.name_layout);
        columnName = (CustomFontTextView) view.findViewById(R.id.column_name);
        programTitle = (CustomFontTextView) view.findViewById(R.id.program_title);
        programDate = (CustomFontTextView) view.findViewById(R.id.program_date);
        bottomTitleLayout  =(LinearLayout) view.findViewById(R.id.bottom_title_layout);
    }

    public void setfProgram(FProgram fProgram) {
        this.fProgram = fProgram;
    }


    /**
     * 开始播放
     *
     * @return 直播ID
     */
    public String playVideo(boolean isMute) {
        if (null != videoPlayer && null != fProgram && !TextUtils.isEmpty(fProgram.getProgrammeUrl())) {
//            videoPlayer.startPlay();
            videoPlayer.isStartClick = true;
            playerBg.setVisibility(View.GONE);
            videoPlayer.hidePlayIcon();
            videoPlayer.startPlay();
            videoPlayer.setEnabled(true);
            videoPlayer.setMute(isMute);
            return fProgram.getProgrammeId();
        }
        return "";
    }

    public void pauseVideo() {
        if (null != videoPlayer && null != fProgram && !TextUtils.isEmpty(fProgram.getProgrammeUrl())) {
//            videoPlayer.onVideoPause();
            playerBg.setVisibility(View.VISIBLE);
            videoPlayer.onVideoPause();
            videoPlayer.setEnabled(false);
            videoPlayer.release();
        }
    }
    public void releaseVideo() {
        if (null != videoPlayer && null != fProgram && !TextUtils.isEmpty(fProgram.getProgrammeUrl())) {
            videoPlayer.setEnabled(false);
            videoPlayer.release();
            playerBg.setVisibility(View.VISIBLE);
        }
    }

    public String exchangeStatus(boolean isMute) {
        if (null != videoPlayer && null != fProgram && !TextUtils.isEmpty(fProgram.getProgrammeUrl())) {
            if (videoPlayer.isPlaying()) {
                playerBg.setVisibility(View.VISIBLE);
                videoPlayer.onVideoPause();
                return "";
            } else {
                videoPlayer.startPlay();
                videoPlayer.setMute(isMute);
                playerBg.setVisibility(View.GONE);
                return fProgram.getProgrammeId();
            }
        }
        return "";
    }

    public boolean isPlaying() {
        if (null != videoPlayer) {
            return videoPlayer.isPlaying();
        } else {
            return false;
        }
    }

    public BasePlayerView getVideoPlayer() {
        return videoPlayer;
    }

    public interface OnColumnClickListener {
        void onColumnClick(LookBackBean fProgram);
    }

    public interface OnColumnItemClickListener {
        void OnItemClick(FProgram item, int position);

        void OnItemInit(BasePlayerView player, int position);
    }
}
